<?php

class Value_List
    extends Value {

    private static function compare(
        $mValue1,
        $mValue2
        ) {

        return
        	empty($mValue1) || empty($mValue2) ?
        		($mValue1 === $mValue2? 0 : -1) :
        		($mValue1 == $mValue2? 0 : ($mValue1 > $mValue2? 1 : -1))
			;

    }

    public function set(
        $mValue = null
        ) {

        if(is_array($mValue)) {
            return parent::set($mValue);
        }

        if(empty($mValue)) {
            return parent::set();
        }

        return $this->set(array_map("trim", explode(",", $mValue)));

    }

    public function isEmpty() {

    	return empty($this->mValue);

	}

    public function isEquals(
        $mValue
        ) {

		if($this->mValue === null) {
			return $mValue === null;
		}

        return is_array($mValue) &&
            count($this->mValue) == count($mValue) &&
            count(array_uintersect($this->mValue, $mValue, "Value_List::compare")) == count($this->mValue)
            ;

    }

    public function isContains(
        $mValue
        ) {

		if($this->mValue === null) {
			return $mValue === null;
		}

        if(is_array($mValue)) {
        	return
        		count(
        			array_udiff(
        				$mValue,
        				array_uintersect(
        					$this->mValue,
        					$mValue,
        					"Value_List::compare"
        					),
						"Value_List::compare"
						)
					) == 0
				;
        }

        return in_array($mValue, $this->mValue);

    }

}

?>